﻿using System;
using System.Configuration;
using System.Web;

namespace UwaySoft.EsheetServer.BizLogic
{
    public class ConfigHelper
    {
        /// <summary>
        /// 本地存放XML文件路径
        /// </summary>
        public static string SaveToLocalPath
        {
            get
            {
#if DEBUG
                return @"D:\";
#else
                return  HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["SaveToLocalPath"]);
#endif
            }
        }
        /// <summary>
        /// 本地存放上传文件路径
        /// </summary>
        public static string SourceFilePath
        {
            get
            {
                return GetPhysicalPath(ConfigurationManager.AppSettings["SourceFilePath"]);
            }
        }
        /// <summary>
        /// 用户地市配置
        /// </summary>
        public static string UserCityConfigPath
        {
            get 
            { 
#if DEBUG
                return @"D:\UwaySoftESheetServer\src\UwaySoft.EsheetServer.Service\Config\UserCitys.config";
#else
                return GetPhysicalPath(@"~/Config/UserCitys.config"); 
#endif
            }
        }
        /// <summary>
        /// 获取实际物理路径
        /// </summary>
        /// <param name="virtualPath">虚拟路径</param>
        /// <returns></returns>
        public static string GetPhysicalPath(string virtualPath)
        {
            if (string.IsNullOrEmpty(virtualPath))
            {
                throw new ArgumentNullException("virtualPath");
            }
            return HttpContext.Current.Server.MapPath(virtualPath);
        }
    }
}
